/**
 * @author 吴汶
 * @since 2022/10/12
 * 13:54
 */
package com.windgo.controller.admin;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.windgo.bean.MarketKeyword;
import com.windgo.bean.common.*;
import com.windgo.bean.keywordvo.DateVo;
import com.windgo.service.KeywordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/keyword")
public class AdminKeyWordController {
    //http://182.92.235.201:8083/admin/keyword/list?page=1&limit=20&sort=add_time&order=desc
    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    @RequiresPermissions("perms[admin:keyword:list]")
    public BaseRespVo list(BasePageInfo basePageInfo, String keyword, String url) {
        // CommonData<MarketKeyword> data=keywordService.list(basePageInfo);
        //return BaseRespVo.ok(data);
        CommonData<MarketKeyword> data = keywordService.search(basePageInfo, keyword, url);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    @RequiresPermissions("perms[admin:keyword:delete]")
    public BaseRespVo delete(@RequestBody MarketKeyword marketKeyword) {
        int i = keywordService.delete(marketKeyword.getId());
        //  System.out.println(marketKeyword.getId());
        if (i != 1) {
            return null;
        }
        return BaseRespVo.ok1();
    }

    @PostMapping("create")
    @RequiresPermissions("perms[admin:keyword:create]")
    public BaseRespVo create(@RequestBody MarketKeyword marketKeyword) {
        MarketKeyword data = keywordService.insert(marketKeyword);
        return BaseRespVo.ok(data);
    }
    @PostMapping("update")
    @RequiresPermissions("perms[admin:keyword:update]")
    public BaseRespVo update(@RequestBody MarketKeyword marketKeyword){
        MarketKeyword data=keywordService.update(marketKeyword);
        return BaseRespVo.ok(data);
    }
}
